package helen.core.tools.gridcontrol;


import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;


/*
 * һ�����ؼ�
 * 
 */
public class GridDataView extends HorizontalScrollView {
	

	private TableLayout tableLayout; //��񲼾�
	private TableLayout headtableLayout; //��ͷ����
	
	//���ֲ���
	private int headColor = Color.argb(250, 220, 220, 220);
	public int headHeight = 30;
	public int headtextsize=13;
	private int headtextColor = Color.BLACK;
	private int headMaxEms = 10;
	
	private int backgroudColor = Color.WHITE;
	private int cellMaxEms = 10;
	private int cellTextColor = Color.BLACK;
	private int cellTextSize = 13;

	public int cellHeight =30;
	private int[] headcolwidth;

	
	public GridDataView(Context context, AttributeSet attrs) {
		
		super(context, attrs);
		initWidge();
	
	}

	
	/*
	 * ���ñ��ı���ͷ
	 */
	public void setTableHeaders(String[] header,int[] headcolwidth){
	
		this.headcolwidth=headcolwidth;
		AddHeadRow  row = new AddHeadRow(getContext(), header);
		row.setBackgroundColor(headColor);
		row.setHeadColWidth(headcolwidth);
		row.setTextMaxEms(headMaxEms);
		row.setTextClor(headtextColor);
		row.setHeadRowHeight(headHeight);
		row.setheadTextsize(headtextsize);
		headtableLayout.addView(row.addTableRow());
	
	}
	

	/*******************����     **************/
	/*
	 * ����µ�һ�У�Ŀǰ�İ汾��֧�ֱ������ͼ�������Ϣ
	 * @@param objects 
	 * ��ӵ�����
	 */
	public void  addNewRow(Object[] objects){

		AddContentsRow addContentsRow = new AddContentsRow(getContext(), objects,this.headcolwidth);
		addContentsRow.setBackColor(backgroudColor);
		addContentsRow.setTextColor(cellTextColor);
		addContentsRow.setTextMaxEms(cellMaxEms);
		addContentsRow.setTextSize(cellTextSize);
		addContentsRow.setRowHeight(cellHeight);
		tableLayout.addView(addContentsRow.addTableRow());

	}
	


	
	public void setTableCellBaackgroundColor(int color){
		this.backgroudColor = color;
	}
	/*
	 * �������ʾ�������֣���������ÿһ����ʾ���ֳ�
	 */
	
	public void setTableCellMaxEms(int length){
		this.cellMaxEms = length;
	}
	public void setTableCellTextSize(int size){
		this.cellTextSize = size;
	}
	public void setTableCellTextColor(int color){
		this.cellTextColor = color;
	}
	public void setTableCellHeight(int height){
		this.cellHeight = height;
	}
	
	

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		super.onLayout(changed, l, t, r, b);
	}
	
	/*
	 * ����ĳ�ʼ��
	 */
	private  void initWidge(){

		this.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

		LinearLayout headLayout=new LinearLayout(getContext());
		headLayout.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
		headtableLayout=new TableLayout(getContext());  //��ͷ����
		headtableLayout.setStretchAllColumns(true);  //���е��ж����Ա�����
		headtableLayout.setBackgroundColor(Color.BLACK);//������ɫ�����ÿ�϶��ʵ�ֱ߿�
		headLayout.addView(headtableLayout);

		LinearLayout GridLinearLayout=new LinearLayout(getContext());
		GridLinearLayout.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		GridLinearLayout.setOrientation(LinearLayout.VERTICAL);
		
		//��ֱ�Ĺ�����
		ScrollView mScrollView = new ScrollView(getContext());
		mScrollView.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		mScrollView.setFillViewport(true);

		tableLayout = new TableLayout(getContext());  //��񲼾�

		tableLayout.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		tableLayout.setStretchAllColumns(true);  //���е��ж����Ա�����
		//tableLayout.setBackgroundColor(Color.BLACK);//������ɫ�����ÿ�϶��ʵ�ֱ߿�
		GridLinearLayout.addView(headLayout);

		mScrollView.addView(tableLayout);
		GridLinearLayout.addView(mScrollView);

		this.addView(GridLinearLayout);
		
	}
	


}